package com.hankol.message.bean;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Base64;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.baselibrary.utils.ScreenUtils;
import com.baselibrary.utils.SpUtils;
import com.hankol.message.R;

import java.util.ArrayList;
import java.util.List;

import io.rong.imkit.RongIM;
import io.rong.imkit.conversation.extension.IExtensionModule;
import io.rong.imkit.conversation.extension.RongExtension;
import io.rong.imkit.conversation.extension.RongExtensionManager;
import io.rong.imkit.conversation.extension.component.emoticon.IEmoticonTab;
import io.rong.imkit.conversation.extension.component.plugin.FilePlugin;
import io.rong.imkit.conversation.extension.component.plugin.IPluginModule;
import io.rong.imkit.conversation.extension.component.plugin.ImagePlugin;
import io.rong.imlib.IRongCallback;
import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.Message;
import io.rong.sight.SightExtensionModule;


/**
 * @author 关忆北丶
 * @description:
 * @date :2021/4/13 14:49
 * <p>
 * 产出 +号 下面的弹窗内容
 */
public class ProduceModule {

    public static boolean isGroup = false;
    private static ProduceModule mProduceModuleInstance;

    public ProduceModule() {
    }


    public static ProduceModule getInstance() {
        if (mProduceModuleInstance == null) {
            synchronized (SpUtils.class) {
                if (mProduceModuleInstance == null) {
                    mProduceModuleInstance = new ProduceModule();
                }
            }
        }
        return mProduceModuleInstance;
    }

    public IPluginModule getProduceIPluginModule(int type) {
        switch (type) {
            case 1:
                //图片
                return new ReImagePlugin();
//            case 2:
//                //小视频
//                return (IPluginModule) new ReSightPlugin();
//            case 3:
//                //位置
//                return new ReDefaultLocationPlugin();
            case 4:
                //文件
                return new ReFilePlugin();
            default:
                return null;
        }
    }

    /**
     * 注销原来的控件
     */
    public void upExtensionModule() {
        List<IExtensionModule> moduleList = RongExtensionManager.getInstance().getExtensionModules();
        IExtensionModule defaultModule = null;
        SightExtensionModule mSightModule = null;//小视频
        if (moduleList != null) {
            for (IExtensionModule module : moduleList) {

                if (module instanceof IExtensionModule) {
                    defaultModule = module;
                }
//                if (module instanceof SightExtensionModule) {
//                    mSightModule = (SightExtensionModule) module;
//                }
            }

//            if (mSightModule != null) {
//                RongExtensionManager.getInstance().unregisterExtensionModule((IExtensionModule) mSightModule);
//            }

            if (defaultModule != null) {
                RongExtensionManager.getInstance().unregisterExtensionModule(defaultModule);
            }
            RongExtensionManager.getInstance().registerExtensionModule(new MyExtensionModule());

        }

    }

    public class MyExtensionModule implements IExtensionModule {


        @Override
        public void onInit(Context context, String s) {

        }

        @Override
        public void onAttachedToExtension(Fragment fragment, RongExtension rongExtension) {

        }

        @Override
        public void onDetachedFromExtension() {

        }

        @Override
        public void onReceivedMessage(Message message) {

        }

        @Override
        public List<IPluginModule> getPluginModules(Conversation.ConversationType conversationType) {
            List<IPluginModule> pluginModules = new ArrayList<>();
            pluginModules.clear();
            pluginModules.add(getProduceIPluginModule(1));
            pluginModules.add(getProduceIPluginModule(2));
            pluginModules.add(getProduceIPluginModule(3));
            //pluginModules.add(getProduceIPluginModule(4));
            if (!ProduceModule.isGroup) {
                return pluginModules;
            }
            boolean isAdvisor = SpUtils.getInstance().getLoadUserBean().getData().getIsAdvisor() == 1;
            if (!isAdvisor) {
                //是群主 但不是服务专员
                pluginModules.add(getProduceIPluginModule(6));
            } else if (  isAdvisor) {
                //是群主，是服务专员
                pluginModules.add(getProduceIPluginModule(5));
                pluginModules.add(getProduceIPluginModule(6));
                pluginModules.add(getProduceIPluginModule(7));
            }
            // ProduceModule.groupId = "";
            //ProduceModule.isGroup = false;
            return pluginModules;
        }

        @Override
        public List<IEmoticonTab> getEmoticonTabs() {
            return null;
        }

        @Override
        public void onDisconnect() {

        }
    }

    /**
     * 图片
     */
    public static class ReImagePlugin extends ImagePlugin {

        @Override
        public Drawable obtainDrawable(Context context) {
            return context.getResources().getDrawable(R.drawable.ic_winetour_album);
        }
    }

    /**
     * 文件
     */
    public static class ReFilePlugin extends FilePlugin {

        @Override
        public Drawable obtainDrawable(Context context) {
            return context.getResources().getDrawable(R.drawable.ic_winetour_file);
        }
    }


}
